/*
 * Copyright (c) 2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef MSDP_ICOMMUNICATE_ADAPTER_H
#define MSDP_ICOMMUNICATE_ADAPTER_H

#include <functional>
#include <memory>
#include <spatial_common.h>

namespace OHOS {
namespace Msdp {
class ICommunicateInterface {
public:
    enum {
        ERROR_NO_NETWORK = 0,
        ERROR_DISCOVER_FAILED,
        ERROR_CONNECT_FAILED,
        ERROR_SESSION_FAILED,
        ERROR_SEND_FAILED,
        ERROR_RECEIVE_FALIED,
        ERROR_UNKNOWN,
    };

    class RemoteListener {
    public:
        virtual void OnPublishSuccess() = 0;
        virtual void OnDiscoverStart() = 0;
        virtual void OnDiscoverDevice(const DeviceInfo& device) = 0;
        virtual void OnDiscoverEnd() = 0;
        virtual void OnGetSuccess(const std::vector<DeviceInfo> &deviceInfoList) = 0;
        virtual void OnGetFail(const std::vector<DeviceInfo> &deviceInfoList) = 0;
        virtual void OnConnected(const std::string& networkId) = 0;
        virtual void OnDisconnected() = 0;
        virtual int32_t OnSessionOpened(int sessionId, int result) = 0;
        virtual void OnSessionClosed(int sessionId) = 0;
        virtual void OnBytesReceived(int sessionId, const void *data, unsigned int dataLen) = 0;
        virtual void OnMessageReceived(int sessionId, const void *data, unsigned int dataLen) = 0;
        virtual void OnError(int error);
        virtual void OnDeviceOnline(const DeviceInfo& device) = 0;
        virtual void OnDeviceReady(const DeviceInfo& device) = 0;
        virtual void OnDeviceOffline(const DeviceInfo& device) = 0;
        virtual void OnDeviceChanged(const DeviceInfo& device) = 0;
    };

    ICommunicateInterface() = default;
    virtual ~ICommunicateInterface() = default;
    virtual void RegisterListoner(const std::shared_ptr<RemoteListener>& remoteListener) = 0;
    virtual int PublishService() = 0;
    virtual int GetTrustDeviceList() = 0;
    virtual DeviceInfo GetLocalDeviceInfo() = 0;
    virtual int StartDiscovery() = 0;
    virtual int StopDiscovery() = 0;
    virtual int Connect(const DeviceInfo& device) = 0;
    virtual int Disconnect() = 0;
    virtual int CreateSessionServer() = 0;
    virtual int RemoveSessionServer() = 0;
    virtual int RegisterDevStateCallback() = 0;
    virtual int UnRegisterDevStateCallback() = 0;
    virtual int OpenSession(const std::string &peerDeviceId, int &sessionId) = 0;
    virtual int CloseSession(int32_t sessionId) = 0;
    virtual bool IsServer(int32_t sessionId) = 0;
    virtual int SendBytes(int sessionId, const void *data, unsigned int len) = 0;
    virtual int SendMessage(int sessionId, const void *data, unsigned int len) = 0;
    virtual int GetPeerDeviceId(int sessionId, std::string &peerDeviceId) = 0;
};
} // namespace Msdp
} // namespace OHOS

#endif // MSDP_ICOMMUNICATE_ADAPTER_H